<template>
    <!-- 对话框表单 -->
    <el-dialog
        class="ba-operate-dialog"
        :close-on-click-modal="false"
        :model-value="baTable.form.operate ? true : false"
        @close="baTable.toggleForm"
    >
        <template #header>
            <div class="title" v-drag="['.ba-operate-dialog', '.el-dialog__header']" v-zoom="'.ba-operate-dialog'">
                {{ baTable.form.operate ? t(baTable.form.operate) : '' }}
            </div>
        </template>
        <el-scrollbar v-loading="baTable.form.loading" class="ba-table-form-scrollbar">
            <div
                class="ba-operate-form"
                :class="'ba-' + baTable.form.operate + '-form'"
                :style="'width: calc(100% - ' + baTable.form.labelWidth! / 2 + 'px)'"
            >
                <el-form
                    v-if="!baTable.form.loading"
                    ref="formRef"
                    @keyup.enter="baTable.onSubmit(formRef)"
                    :model="baTable.form.items"
                    label-position="right"
                    :label-width="baTable.form.labelWidth + 'px'"
                    :rules="rules"
                >
                <FormItem :label="t('bill.INVOICEID')" type="string" v-model="baTable.form.items!.INVOICEID" prop="INVOICEID" :input-attr="{ placeholder: t('Please input field', { field: t('bill.INVOICEID') }) }" />
                <FormItem :label="t('bill.TZID')" type="string" v-model="baTable.form.items!.TZID" prop="TZID" :input-attr="{ placeholder: t('Please input field', { field: t('bill.TZID') }) }" />
                <FormItem :label="t('bill.INOUT')" type="string" v-model="baTable.form.items!.INOUT" prop="INOUT" :input-attr="{ placeholder: t('Please input field', { field: t('bill.INOUT') }) }" />
                <FormItem :label="t('bill.BILLTYPE')" type="radio" v-model="baTable.form.items!.BILLTYPE" prop="BILLTYPE" :data="{ content: { 1: t('bill.BILLTYPE 1') } }" :input-attr="{ placeholder: t('Please select field', { field: t('bill.BILLTYPE') }) }" />
                <FormItem :label="t('bill.CORPCODE')" type="string" v-model="baTable.form.items!.CORPCODE" prop="CORPCODE" :input-attr="{ placeholder: t('Please input field', { field: t('bill.CORPCODE') }) }" />
                <FormItem :label="t('bill.ITEMCODE')" type="string" v-model="baTable.form.items!.ITEMCODE" prop="ITEMCODE" :input-attr="{ placeholder: t('Please input field', { field: t('bill.ITEMCODE') }) }" />
                <FormItem :label="t('bill.MONEYTYPE')" type="string" v-model="baTable.form.items!.MONEYTYPE" prop="MONEYTYPE" :input-attr="{ placeholder: t('Please input field', { field: t('bill.MONEYTYPE') }) }" />
                <FormItem :label="t('bill.MONEY')" type="number" prop="MONEY" v-model.number="baTable.form.items!.MONEY" :input-attr="{ step: '0.01', placeholder: t('Please input field', { field: t('bill.MONEY') }) }" />
                <FormItem :label="t('bill.AUTOADD')" type="string" v-model="baTable.form.items!.AUTOADD" prop="AUTOADD" :input-attr="{ placeholder: t('Please input field', { field: t('bill.AUTOADD') }) }" />
                <FormItem :label="t('bill.TOINVOICE')" type="string" v-model="baTable.form.items!.TOINVOICE" prop="TOINVOICE" :input-attr="{ placeholder: t('Please input field', { field: t('bill.TOINVOICE') }) }" />
                <FormItem :label="t('bill.BILLCLASS')" type="string" v-model="baTable.form.items!.BILLCLASS" prop="BILLCLASS" :input-attr="{ placeholder: t('Please input field', { field: t('bill.BILLCLASS') }) }" />
                <FormItem :label="t('bill.BILLDATE')" type="datetime" v-model="baTable.form.items!.BILLDATE" prop="BILLDATE" :input-attr="{ placeholder: t('Please select field', { field: t('bill.BILLDATE') }) }" />
                <FormItem :label="t('bill.ACTUALMONEY')" type="number" prop="ACTUALMONEY" v-model.number="baTable.form.items!.ACTUALMONEY" :input-attr="{ step: '0.01', placeholder: t('Please input field', { field: t('bill.ACTUALMONEY') }) }" />
                <FormItem :label="t('bill.CHECKED')" type="string" v-model="baTable.form.items!.CHECKED" prop="CHECKED" :input-attr="{ placeholder: t('Please input field', { field: t('bill.CHECKED') }) }" />
                <FormItem :label="t('bill.VOUCHERNO')" type="string" v-model="baTable.form.items!.VOUCHERNO" prop="VOUCHERNO" :input-attr="{ placeholder: t('Please input field', { field: t('bill.VOUCHERNO') }) }" />
                <FormItem :label="t('bill.RATIO')" type="string" v-model="baTable.form.items!.RATIO" prop="RATIO" :input-attr="{ placeholder: t('Please input field', { field: t('bill.RATIO') }) }" />
                <FormItem :label="t('bill.RATE')" type="number" prop="RATE" v-model.number="baTable.form.items!.RATE" :input-attr="{ step: '0.0000000001', placeholder: t('Please input field', { field: t('bill.RATE') }) }" />
                <FormItem :label="t('bill.OPNAME')" type="string" v-model="baTable.form.items!.OPNAME" prop="OPNAME" :input-attr="{ placeholder: t('Please input field', { field: t('bill.OPNAME') }) }" />
                <FormItem :label="t('bill.OPDEPT')" type="string" v-model="baTable.form.items!.OPDEPT" prop="OPDEPT" :input-attr="{ placeholder: t('Please input field', { field: t('bill.OPDEPT') }) }" />
                <FormItem :label="t('bill.OPDATETIME')" type="datetime" v-model="baTable.form.items!.OPDATETIME" prop="OPDATETIME" :input-attr="{ placeholder: t('Please select field', { field: t('bill.OPDATETIME') }) }" />
                <FormItem :label="t('bill.CHECKER')" type="string" v-model="baTable.form.items!.CHECKER" prop="CHECKER" :input-attr="{ placeholder: t('Please input field', { field: t('bill.CHECKER') }) }" />
                <FormItem :label="t('bill.CHECKDATETIME')" type="datetime" v-model="baTable.form.items!.CHECKDATETIME" prop="CHECKDATETIME" :input-attr="{ placeholder: t('Please select field', { field: t('bill.CHECKDATETIME') }) }" />
                <FormItem :label="t('bill.REMARK')" type="string" v-model="baTable.form.items!.REMARK" prop="REMARK" :input-attr="{ placeholder: t('Please input field', { field: t('bill.REMARK') }) }" />
                <FormItem :label="t('bill.MARKNO')" type="string" v-model="baTable.form.items!.MARKNO" prop="MARKNO" :input-attr="{ placeholder: t('Please input field', { field: t('bill.MARKNO') }) }" />
                <FormItem :label="t('bill.yfmoney')" type="number" prop="yfmoney" v-model.number="baTable.form.items!.yfmoney" :input-attr="{ step: '0.01', placeholder: t('Please input field', { field: t('bill.yfmoney') }) }" />
                <FormItem :label="t('bill.flag1')" type="string" v-model="baTable.form.items!.flag1" prop="flag1" :input-attr="{ placeholder: t('Please input field', { field: t('bill.flag1') }) }" />
                <FormItem :label="t('bill.TAXRATE')" type="number" prop="TAXRATE" v-model.number="baTable.form.items!.TAXRATE" :input-attr="{ step: '0.01', placeholder: t('Please input field', { field: t('bill.TAXRATE') }) }" />
                <FormItem :label="t('bill.CNTRNO')" type="string" v-model="baTable.form.items!.CNTRNO" prop="CNTRNO" :input-attr="{ placeholder: t('Please input field', { field: t('bill.CNTRNO') }) }" />
                <FormItem :label="t('bill.STARTDATE')" type="datetime" v-model="baTable.form.items!.STARTDATE" prop="STARTDATE" :input-attr="{ placeholder: t('Please select field', { field: t('bill.STARTDATE') }) }" />
                <FormItem :label="t('bill.ENDDATE')" type="datetime" v-model="baTable.form.items!.ENDDATE" prop="ENDDATE" :input-attr="{ placeholder: t('Please select field', { field: t('bill.ENDDATE') }) }" />
                <FormItem :label="t('bill.AMOUNT')" type="string" v-model="baTable.form.items!.AMOUNT" prop="AMOUNT" :input-attr="{ placeholder: t('Please input field', { field: t('bill.AMOUNT') }) }" />
                <FormItem :label="t('bill.PRICETYPE')" type="string" v-model="baTable.form.items!.PRICETYPE" prop="PRICETYPE" :input-attr="{ placeholder: t('Please input field', { field: t('bill.PRICETYPE') }) }" />
                <FormItem :label="t('bill.JOBNO')" type="string" v-model="baTable.form.items!.JOBNO" prop="JOBNO" :input-attr="{ placeholder: t('Please input field', { field: t('bill.JOBNO') }) }" />
                <FormItem :label="t('bill.TJFLAG')" type="string" v-model="baTable.form.items!.TJFLAG" prop="TJFLAG" :input-attr="{ placeholder: t('Please input field', { field: t('bill.TJFLAG') }) }" />
                <FormItem :label="t('bill.TJOP')" type="string" v-model="baTable.form.items!.TJOP" prop="TJOP" :input-attr="{ placeholder: t('Please input field', { field: t('bill.TJOP') }) }" />
                <FormItem :label="t('bill.TJDATETIME')" type="datetime" v-model="baTable.form.items!.TJDATETIME" prop="TJDATETIME" :input-attr="{ placeholder: t('Please select field', { field: t('bill.TJDATETIME') }) }" />
                </el-form>
            </div>
        </el-scrollbar>
        <template #footer>
            <div :style="'width: calc(100% - ' + baTable.form.labelWidth! / 1.8 + 'px)'">
                <el-button @click="baTable.toggleForm('')">{{ t('Cancel') }}</el-button>
                <el-button v-blur :loading="baTable.form.submitLoading" @click="baTable.onSubmit(formRef)" type="primary">
                    {{ baTable.form.operateIds && baTable.form.operateIds.length > 1 ? t('Save and edit next item') : t('Save') }}
                </el-button>
            </div>
        </template>
    </el-dialog>
</template>

<script setup lang="ts">
import { reactive, ref, inject } from 'vue'
import { useI18n } from 'vue-i18n'
import type baTableClass from '/@/utils/baTable'
import FormItem from '/@/components/formItem/index.vue'
import type { ElForm, FormItemRule } from 'element-plus'
import { buildValidatorData } from '/@/utils/validate'


const formRef = ref<InstanceType<typeof ElForm>>()
const baTable = inject('baTable') as baTableClass

const { t } = useI18n()

const rules: Partial<Record<string, FormItemRule[]>> = reactive({
    TZID: [buildValidatorData({name: 'required', title: t('bill.TZID')})],
    INOUT: [buildValidatorData({name: 'required', title: t('bill.INOUT')})],
    BILLTYPE: [buildValidatorData({name: 'required', message: t('Please select field', { field: t('bill.BILLTYPE') })})],
    CORPCODE: [buildValidatorData({name: 'required', title: t('bill.CORPCODE')})],
    ITEMCODE: [buildValidatorData({name: 'required', title: t('bill.ITEMCODE')})],
    MONEYTYPE: [buildValidatorData({name: 'required', title: t('bill.MONEYTYPE')})],
    MONEY: [buildValidatorData({name: 'required', title: t('bill.MONEY')})],
    AUTOADD: [buildValidatorData({name: 'required', title: t('bill.AUTOADD')})],
    TOINVOICE: [buildValidatorData({name: 'required', title: t('bill.TOINVOICE')})],
    BILLCLASS: [buildValidatorData({name: 'required', title: t('bill.BILLCLASS')})],
    BILLDATE: [buildValidatorData({name: 'required', message: t('Please select field', { field: t('bill.BILLDATE') })}), buildValidatorData({name: 'date', message: t('Please enter the correct field', { field: t('bill.BILLDATE') })})],
    ACTUALMONEY: [buildValidatorData({name: 'required', title: t('bill.ACTUALMONEY')})],
    CHECKED: [buildValidatorData({name: 'required', title: t('bill.CHECKED')})],
    OPDATETIME: [buildValidatorData({name: 'date', message: t('Please enter the correct field', { field: t('bill.OPDATETIME') })})],
    CHECKDATETIME: [buildValidatorData({name: 'date', message: t('Please enter the correct field', { field: t('bill.CHECKDATETIME') })})],
    STARTDATE: [buildValidatorData({name: 'date', message: t('Please enter the correct field', { field: t('bill.STARTDATE') })})],
    ENDDATE: [buildValidatorData({name: 'date', message: t('Please enter the correct field', { field: t('bill.ENDDATE') })})],
    TJDATETIME: [buildValidatorData({name: 'date', message: t('Please enter the correct field', { field: t('bill.TJDATETIME') })})],
})

</script>

<style scoped lang="scss"></style>
